home *** CD-ROM | disk | FTP | other *** search
/ Champak Vol A-4 / (Vol A-4) Vol. A4.iso / Games / smashing.swf / scripts / frame_40 / DoAction.as
Text File  |  2008-03-12  |  6KB  |  194 lines

  1. function ballActions(ballpath)
  2. {
  3.    if(!gamePaused)
  4.    {
  5.       ball = eval(ballPath);
  6.       if(ball.nextSpeedIncrease < getTimer() && maxSpeedups >= ball.speedIncreaseCounter)
  7.       {
  8.          if(maxSpeed >= makePositive(ball.SpeedX,true) && maxSpeed >= makePositive(ball.SpeedY,true))
  9.          {
  10.             if(ball.SpeedX >= 0)
  11.             {
  12.                ball.SpeedX += speedIncreaseSteps;
  13.             }
  14.             else
  15.             {
  16.                ball.SpeedX -= speedIncreaseSteps;
  17.             }
  18.             if(ball.SpeedY >= 0)
  19.             {
  20.                ball.SpeedY += speedIncreaseSteps;
  21.             }
  22.             else
  23.             {
  24.                ball.SpeedY -= speedIncreaseSteps;
  25.             }
  26.             ball.nextSpeedIncrease = getTimer() + speedIncreaseDelay;
  27.             ball.speedIncreaseCounter = ball.speedIncreaseCounter + 1;
  28.          }
  29.       }
  30.       ball.TargetX = ball._x - ball.SpeedX;
  31.       ball.TargetY = ball._y - ball.SpeedY;
  32.       if(ball.TargetX >= rightWall)
  33.       {
  34.          sndHitWall.start();
  35.          while(ball.TargetX >= rightWall)
  36.          {
  37.             ball.TargetX--;
  38.          }
  39.          ball.SpeedX = - ball.SpeedX;
  40.          ballLastBounced = getTimer();
  41.       }
  42.       if(leftWall >= ball.TargetX)
  43.       {
  44.          sndHitWall.start();
  45.          while(leftWall >= ball.TargetX)
  46.          {
  47.             ball.TargetX = ball.TargetX + 1;
  48.          }
  49.          ball.SpeedX = - ball.SpeedX;
  50.          ballLastBounced = getTimer();
  51.       }
  52.       if(topWall >= ball.TargetY)
  53.       {
  54.          sndHitWall.start();
  55.          while(topWall >= ball.TargetY)
  56.          {
  57.             ball.TargetY = ball.TargetY + 1;
  58.          }
  59.          ball.SpeedY = - ball.SpeedY;
  60.          ballLastBounced = getTimer();
  61.       }
  62.       if(ball.TargetY >= bottomWall)
  63.       {
  64.          ball.removeMovieClip();
  65.          ballsActive--;
  66.          if(ballsActive < 1)
  67.          {
  68.             readyToShootBall = false;
  69.             padsLeft--;
  70.             menu.txtPadsLeft = padsLeft;
  71.             sndExplosionShip.start();
  72.             pad.left.gotoState = "explode";
  73.             pad.right.gotoState = "explode";
  74.             pad.left.play();
  75.             pad.right.play();
  76.          }
  77.          if(padsLeft < 1 && !gameOver)
  78.          {
  79.             padsLeft = 0;
  80.             gotoAndPlay(137);
  81.             gameOver = true;
  82.          }
  83.       }
  84.       ball.pixelsMoveX = (ball.TargetX - ball._x) / iterations;
  85.       ball.pixelsMoveY = (ball.TargetY - ball._y) / iterations;
  86.       b = 1;
  87.       while(iterations >= b)
  88.       {
  89.          ball.testMoveXTemp = ball.testMoveX;
  90.          ball.testMoveYTemp = ball.testMoveY;
  91.          ball.testMoveX = ball._x + ball.pixelsMoveX * b;
  92.          ball.testMoveY = ball._y + ball.pixelsMoveY * b;
  93.          if(bricks.hitTest(ball.testMoveX,ball.testMoveY,true))
  94.          {
  95.             hitBrick(ball);
  96.             break;
  97.          }
  98.          if(pad.hitTest(ball.testMoveX,ball.testMoveY,true))
  99.          {
  100.             if(ballHitPadPause < getTimer())
  101.             {
  102.                ballHitPad(ball);
  103.                ballHitPadPause = getTimer() + 160;
  104.             }
  105.             break;
  106.          }
  107.          b++;
  108.       }
  109.       ball._x = ball.TargetX;
  110.       ball._y = ball.TargetY;
  111.    }
  112. }
  113. function ballBounce(ball, movieClipHit, hitSurface, hitBrickTooFast)
  114. {
  115.    movieClipHit = eval(movieClipHit);
  116.    if(hitSurface == "top")
  117.    {
  118.       while(bricks.hitTest(ball.testMoveX,ball.testMoveY,true))
  119.       {
  120.          ball.testMoveY--;
  121.       }
  122.       ball.TargetX = ball.testMoveX;
  123.       ball.TargetY = ball.testMoveY;
  124.       ball.SpeedY = - ball.SpeedY;
  125.    }
  126.    else if(hitSurface == "bottom")
  127.    {
  128.       while(bricks.hitTest(ball.testMoveX,ball.testMoveY,true))
  129.       {
  130.          ball.testMoveY = ball.testMoveY + 1;
  131.       }
  132.       ball.TargetX = ball.testMoveX;
  133.       ball.TargetY = ball.testMoveY;
  134.       ball.SpeedY = - ball.SpeedY;
  135.    }
  136.    else if(hitSurface == "right")
  137.    {
  138.       while(bricks.hitTest(ball.testMoveX,ball.testMoveY,true))
  139.       {
  140.          ball.testMoveX = ball.testMoveX + 1;
  141.       }
  142.       ball.SpeedX = - ball.SpeedX;
  143.       ball.TargetX = ball.testMoveX;
  144.       ball.TargetY = ball.testMoveY;
  145.    }
  146.    else if(hitSurface == "left")
  147.    {
  148.       while(bricks.hitTest(ball.testMoveX,ball.testMoveY,true))
  149.       {
  150.          ball.testMoveX--;
  151.       }
  152.       ball.TargetX = ball.testMoveX;
  153.       ball.TargetY = ball.testMoveY;
  154.       ball.SpeedX = - ball.SpeedX;
  155.    }
  156. }
  157. function generateBall(fromPad, x, y)
  158. {
  159.    targetClip = eval(mc);
  160.    clipCounter++;
  161.    attachMovie("mcBall","mcBall" + _root.clipCounter,_root.clipCounter);
  162.    this["mcBall" + _root.clipCounter]._x = x;
  163.    this["mcBall" + _root.clipCounter]._y = y;
  164.    ballsActive++;
  165.    do
  166.    {
  167.       this["mcBall" + _root.clipCounter].SpeedX = random(startSpeed * 2) - startSpeed;
  168.    }
  169.    while(this["mcBall" + _root.clipCounter].SpeedX == 0);
  170.    
  171.    if(fromPad)
  172.    {
  173.       sndReleaseBall.start();
  174.       this["mcBall" + _root.clipCounter].SpeedY = startSpeed;
  175.    }
  176.    else
  177.    {
  178.       do
  179.       {
  180.          this["mcBall" + _root.clipCounter].SpeedY = random(startSpeed * 2) - startSpeed;
  181.       }
  182.       while(this["mcBall" + _root.clipCounter].SpeedY == 0);
  183.       
  184.    }
  185. }
  186. speedIncreaseDelay = 2000;
  187. speedIncreaseSteps = 0.4;
  188. nextSpeedIncrease = getTimer() + speedIncreaseDelay;
  189. maxSpeed = 10;
  190. startSpeed = 5;
  191. maxSpeedups = maxSpeed / speedIncreaseSteps - startSpeed;
  192. iterations = 5;
  193. gotoAndPlay(48);
  194.